define(function(require, exports, module) {
    "use strict";
    var $ = require("$"),
        app = require("dist/application/app"),
        config = app.config,
        method = app.method; 
    window.change_template_path && (function() {

        var done = function($this) {
            var page = $this.attr("name"),
                selected = $this.val();
            $this.closest('li').addClass('selected').siblings().removeClass('selected')
            if (page && selected) {
                method.postd(window.change_template_path, function(d) {
                    if (config.issucceed(d)) {
                        config.msg.suc(d.message || config.lang.modifySuccess)
                        //$this.closest('li').addClass('selected').siblings().removeClass('selected')

                    } else {
                        config.msg.error(d.message || config.lang.modifyError, d.url)
                    }
                }, {
                    page: page,
                    selected: selected
                })
            };
        }

        $(document).on("click", '.list-template li', function() {
            var $this = $(this).find('input[type="radio"]');
            $this.prop("checked", "checked")
            done($this)

        }); 

        // $(document).on("click", '.list-template input[type="radio"] ', function(e) { 
        //     e && e.stopPropagation();
        //     done($(this))
        // })
    })();

    $(document).on("click", '.js_no_submit_template li', function() {
        var $this = $(this),
            $ul = $this.closest("ul");
        $ul.find("li").removeClass('selected');
        $this.find('input[type="radio"]').prop("checked", "checked");
        $this.addClass('selected');
    });
    $(document).on("click", '.js_design_template li', function() {
        var $this = $(this),
            $ul = $this.closest("ul");
        $ul.find("li").removeClass('selected');
        $this.find('input[type="radio"]').trigger("click");
        $this.addClass('selected');
    });
    $(document).on("click", function() {
        $(".js_design_tips").addClass('hide');
    });
    if(!$.cookie("js_design_tips")){
        $(".js_design_tips").removeClass('hide');
        $.cookie("js_design_tips",true);
    }
    
})
